using System.IO;

namespace LuceneSearch.Indexer
{
    public class DirectoryIndexer : IDirectoryVisitor
    {
        private readonly IIndexWriter indexWriter;

        public DirectoryIndexer(IIndexWriter indexWriter)
        {
            this.indexWriter = indexWriter;
        }

        void IDirectoryVisitor.Visit(DirectoryInfo dir)
        {
            IndexDirectory(dir);
        }

        private void IndexDirectory(DirectoryInfo dir)
        {
            foreach (var file in dir.GetFiles())
            {
                indexWriter.IndexFile(file);
            }
        }
    }
}